package com.platform.common.enums;

import lombok.Getter;

import java.util.Arrays;

/**
 * 角色枚举
 */

@Getter
public enum RoleEnum {
    ALL(0, "ROLE_ALL", "白名单URL，登录的所有角色，URL专用"),
    USER(1, "ROLE_USER", "普通用户"),
    AUDIT(2, "ROLE_AUDIT", "平台用户"),
    ADMIN(5, "ROLE_ADMIN", "白名单角色，系统管理员"),
    BANNED(6, "ROLE_BANNED", "黑名单角色，被封禁用户");

    private int type;

    private String name;

    private String cnName;

    RoleEnum(int type, String name, String cnName) {
        this.type = type;
        this.name = name;
        this.cnName = cnName;
    }

    public static RoleEnum getByType(int type) {
        return Arrays.stream(values()).filter(e -> e.getType() == type).findFirst().orElse(null);
    }

    public static RoleEnum getByName(String name) {
        return Arrays.stream(values()).filter(e -> e.getName().equals(name)).findFirst().orElse(null);
    }

}
